package com.bdcom.autotest.interaction.step.remodel;

import com.bdcom.autotest.interaction.bean.DeviceUpdBean;
import com.bdcom.autotest.interaction.bean.TestLog;
import com.bdcom.autotest.interaction.db.DBUtil;
import com.bdcom.autotest.interaction.socket.DataUtil;
import com.bdcom.autotest.interaction.step.IStepHandler;
import com.bdcom.autotest.interaction.step.StepThread;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class SaveLog implements IStepHandler{

	
	@Override
	public boolean runStep(StepThread mainrun) {
//		List<DeviceUpdBean> deviceUpdResultList = mainrun.getUpgradeResult();
//		Map<String, DeviceUpdBean> macToUpdBean = mainrun.getMacToUpdBean();
//		String[] sns = DataUtil.deleteArrayNull(mainrun.getMf().getLeftp().getsns());
//		List<String> passSn = new ArrayList();
//		List<String> failSn = new ArrayList();
//
//		for(DeviceUpdBean updBean:deviceUpdResultList){
//			if(!updBean.getUdpFlag()){
//				failSn.add(updBean.getMac());
//				addTestLog(updBean,"失败");
//			}
//		}
//		for(String sn:sns){
//			if(!failSn.contains(sn)){
//				passSn.add(sn);
//				addTestLog(macToUpdBean.get(sn),"成功");
//			}
//		}
//		mainrun.setResult(passSn);
		return true;
	}

	private void addTestLog(DeviceUpdBean updBean,String result){
		TestLog testLog = new TestLog();
		testLog.setWorkOrder(updBean.getWorkOrderNum());
		testLog.setOemSn(updBean.getOemsn());
		testLog.setBdSn(updBean.getBdsn());
		testLog.setMac(updBean.getMac());
		testLog.setRes(result);
		if(updBean.getResultStr()!=null){
			testLog.setDescr(updBean.getResultStr());
		}else{
			testLog.setDescr("");
		}
		testLog.setTimeStamp(System.currentTimeMillis());
		DBUtil.addTestLog(testLog);
	}
}
